﻿namespace DotRas
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Security.Permissions;

    [ToolboxItem(true), ToolboxBitmap(typeof(RasAutoDialManager), "DotRas.RasAutoDialManager.bmp")]
    public sealed class RasAutoDialManager : Component
    {
        private RasAutoDialAddressCollection _addresses;

        public RasAutoDialManager()
        {
        }

        public RasAutoDialManager(IContainer container)
        {
            if (container != null)
            {
                container.Add(this);
            }
        }

        private void InitializeComponent()
        {
        }

        [RegistryPermission(SecurityAction.Demand, Unrestricted=true)]
        public bool IsAutoDialEnabled(int dialingLocation)
        {
            return RasHelper.GetAutoDialEnable(dialingLocation);
        }

        [RegistryPermission(SecurityAction.Demand, Unrestricted=true)]
        public bool UpdateAutoDialStatus(int dialingLocation, bool enabled)
        {
            return RasHelper.SetAutoDialEnable(dialingLocation, enabled);
        }

        [Browsable(false)]
        public RasAutoDialAddressCollection Addresses
        {
            get
            {
                if (this._addresses == null)
                {
                    this._addresses = new RasAutoDialAddressCollection();
                    this._addresses.Load();
                }
                return this._addresses;
            }
        }

        [DotRas.SRDescription("RADMConnectionQueryTimeoutDesc"), DefaultValue(60), DotRas.SRCategory("CatBehavior")]
        public int ConnectionQueryTimeout
        {
            get
            {
                return RasHelper.GetAutoDialParameter(DotRas.NativeMethods.RASADP.ConnectionQueryTimeout);
            }
            set
            {
                RasHelper.SetAutoDialParameter(DotRas.NativeMethods.RASADP.ConnectionQueryTimeout, value);
            }
        }

        [DotRas.SRCategory("CatBehavior"), DefaultValue(false), DotRas.SRDescription("RADMDisableConnectionQueryDesc")]
        public bool DisableConnectionQuery
        {
            get
            {
                return (RasHelper.GetAutoDialParameter(DotRas.NativeMethods.RASADP.DisableConnectionQuery) != 0);
            }
            set
            {
                int num = 0;
                if (value)
                {
                    num = 1;
                }
                RasHelper.SetAutoDialParameter(DotRas.NativeMethods.RASADP.DisableConnectionQuery, num);
            }
        }

        [DefaultValue(5), DotRas.SRCategory("CatBehavior"), DotRas.SRDescription("RADMFailedConnectionTimeoutDesc")]
        public int FailedConnectionTimeout
        {
            get
            {
                return RasHelper.GetAutoDialParameter(DotRas.NativeMethods.RASADP.FailedConnectionTimeout);
            }
            set
            {
                RasHelper.SetAutoDialParameter(DotRas.NativeMethods.RASADP.FailedConnectionTimeout, value);
            }
        }

        [DotRas.SRCategory("CatBehavior"), DotRas.SRDescription("RADMLogOnSessionDisableDesc"), DefaultValue(false)]
        public bool LogOnSessionDisable
        {
            get
            {
                return (RasHelper.GetAutoDialParameter(DotRas.NativeMethods.RASADP.LogOnSessionDisable) != 0);
            }
            set
            {
                int num = 0;
                if (value)
                {
                    num = 1;
                }
                RasHelper.SetAutoDialParameter(DotRas.NativeMethods.RASADP.LogOnSessionDisable, num);
            }
        }

        [DefaultValue(100), DotRas.SRCategory("CatBehavior"), DotRas.SRDescription("RADMSavedAddressesLimitDesc")]
        public int SavedAddressesLimit
        {
            get
            {
                return RasHelper.GetAutoDialParameter(DotRas.NativeMethods.RASADP.SavedAddressesLimit);
            }
            set
            {
                RasHelper.SetAutoDialParameter(DotRas.NativeMethods.RASADP.SavedAddressesLimit, value);
            }
        }
    }
}

